<?php

namespace app\api\controller\mox;

use app\common\controller\Api;
use app\admin\model\mox\Message as MessageModel;
use app\admin\model\mox\inherit\story\Info as InfoModel;
use app\admin\model\mox\inherit\story\Chapter as ChapterModel;
use app\admin\model\mox\inherit\Character as CharacterModel;
use app\admin\model\mox\play\Info as PlayModel;
use app\admin\model\mox\inherit\Value as ValueModel;
use app\admin\model\mox\inherit\Policy as policyModel;
use app\admin\model\mox\Heritage as HeritageModel;
use app\admin\model\mox\lnformation\Info as lnformationModel;
use \app\admin\model\mox\trends\Info as TrendsModel;
use \app\admin\model\mox\inheritor\Info as InheritorModel;




/**
 * 首页
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页数据
     *
     */
    public function index()
    {
        $playmodel = new PlayModel();
        $informationmodel = new lnformationModel();
        $data = [];
        //获取剧目
        $data['play'] = $playmodel->where('is_perform', 1)->field('id, title, image, brief_introduction')->order('id desc')->limit(4)->select();
        //获取新闻
        $data['information'] = $informationmodel->field('id, title, image, brief_introduction,create_time')->order('id desc')->limit(4)->select();
        $this->success('请求成功', $data);
    }

    /**
     * 添加浏览次数
     *
     */
    public function addNum()
    {
        $type = $this->request->param('type');
        $id = $this->request->param('id');
        switch ($type) {
            case 'play':
                $model = new PlayModel();
                break;
            case 'character':
                $model = new CharacterModel();
                break;
            case 'chapter':
                $model = new ChapterModel();
                break;
            case 'story':
                $model = new InfoModel();
                break;
            case 'value':
                $model = new ValueModel();
                break;
            case 'policy':
                $model = new policyModel();
                break;
            case 'heritage':
                $model = new HeritageModel();
                break;
            case 'information':
                $model = new lnformationModel();
                break;
            case 'play':
                $model = new PlayModel();
                break;
            case 'trends':
                $model = new TrendsModel();
                break;
            case 'inheritor':
                $model = new InheritorModel();
                break;
            default:
                $this->error('类型错误');
        }
        $model->where('id', $id)->setInc('num');
        $this->success('请求成功');
    }
}
